import request from "@/utils/request.ts";
import type
{
    LoginData,UserLoginResponseData,WXLoginResponseData,VisitorInfo,AddVisitorInfoResData,SubmitOrder,
    OrderResponseData,QrCode,PayResult,OneUserInfoResData,CertationTypeResponseData,UserParams,AllOrderResponseData,
    AllUserResponseData,AllOrderStateResponseData,AddOrUpdateUser
}
from "@/api/user/type.ts";

import {LocationQueryValue} from "vue-router";
enum API{
    // 获取手机验证码的url
    GET_VERIFICATION_CODE='/api/sms/send/',
    // 用户登录接口
    USER_LOGIN='/api/user/login',
    //获取微信扫码登录需要参数
    WXLOGIN_URL='/api/user/weixin/getLoginParam',
    //添加就诊人信息
    ADD_VISITOR_INFO='/api/user/patient/auth/save',
    //提交订单
    SUBMITORDER_URL='/api/order/orderInfo/auth/submitOrder/',
    //获取订单
    GETORDERINFO_URL='/api/order/orderInfo/auth/getOrderInfo/',
    //取消订单
    ORDERCANCEL_URL='/api/order/orderInfo/auth/cancelOrder/',
    //获取二维码
    QRCODE_URL='/api/order/weixin/createNative/',
    //查询订单支付的结果
    PAYRESULT_URL='/api/order/weixin/queryPayStatus/',
    //获取当前用户的信息
    USERINFO_URL='/api/user/auth/getUserInfo',
    //获取证件的类型的接口地址
    CERTIFICATIONTYPE_URL='/api/cmn/dict/findByDictCode/',
    //用户认证
    USERCERTATION_URL='/api/user/auth/userAuah',
    //获取用户订单的数据
    USERORDERINFO_URL='/api/order/orderInfo/auth/',
    //获取全部就诊人的信息
    ALLUSER_URL='/api/user/patient/auth/findAll',
    //获取订单的状态
    ORDERSTATE_URL='/api/order/orderInfo/auth/getStatusList',
    //获取中国城市的数据
    CITY_URL='/api/cmn/dict/findByParentId/',
    //添加就诊人
    ADDUSER_URL='/api/user/patient/auth/save',
    //新增就诊人
    UPDATEUSER_URL='/api/user/patient/auth/update',
    //删除就诊人
    DELETEUSER_URL='/api/user/patient/auth/remove/'
}
/**
 * 获取验证码的请求方法
 * @param phone
 */
export const reqVerificationCdoe=(phone:string)=>{
    return request.get<any,any>(API.GET_VERIFICATION_CODE+phone)
}
/**
 *手机号登录
 * @param data
 */
export const reqUserLogin=(data:LoginData)=>{
    return request.post<any,UserLoginResponseData>(API.USER_LOGIN,data)
}
/**
 * 微信登录
 * @param wxRedirectUri
 */
export const reqWxLogin = (wxRedirectUri:string) => request.get<any,WXLoginResponseData>(API.WXLOGIN_URL+`?wxRedirectUri=${wxRedirectUri}`)
/**
 * 添加就诊人信息
 * @param data
 */
export const reqAddVisitorInfo = (data:VisitorInfo)=>{return request.post<any,AddVisitorInfoResData>(API.ADD_VISITOR_INFO,data)}
/**
 * 提交订单
 * @param hoscode
 * @param scheduleId
 * @param patientId
 */
export const reqSubmitOrder = (hoscode: string, scheduleId: string, patientId: number)=>{
    return request.post<any,SubmitOrder>(API.SUBMITORDER_URL+`${hoscode}/${scheduleId}/${patientId}`)
}
/**
 * 获取订单
 * @param id 用户id
 */
export const reqOrderInfo = (id:string) =>{
    return request.get<any,OrderResponseData>(API.GETORDERINFO_URL+`${id}`)
}
/**
 * 取消订单
 * @param orderId
 */
export const reqCancelOrder = (orderId:string)=>{
    return request.get<any,any>(API.ORDERCANCEL_URL+`${orderId}`)
}
/**
 * 获取二维码
 * @param orderId
 */
export const reqQrCode = (orderId: string | null | LocationQueryValue[])=>{
    return request.get<any,QrCode>(API.QRCODE_URL+`${orderId}`)
}
/**
 * 查询订单支付的结果
 * @param orderId
 */
export const reqQueryState =(orderId:string)=>{
    return request.get<any,PayResult>(API.PAYRESULT_URL+`${orderId}`)
}
/**
 * 获取用户信息
 */
export const reqUserInfo= ()=>{
    return request.get<any,OneUserInfoResData>(API.USERINFO_URL)
}
/**
 * 获取户口类型
 * @param CertificatesType
 */
export const reqCertationType = (CertificatesType='CertificatesType')=>{
    return request.get<any,CertationTypeResponseData>(API.CERTIFICATIONTYPE_URL+`${CertificatesType}`)
}
/**
 * 用户实名认证
 * @param data 用户数据
 */
export const reqUserCertation =(data:UserParams)=>{
    return request.post<any,any>(API.USERCERTATION_URL,data)
}
/**
 * 获取用户订单数据
 */
export const reqAllOrderData = (page:number,limit:number,patientId:string,orderStatus:string)=>{
    console.log(API.USERORDERINFO_URL+`${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`)
    return request.get<any,AllOrderResponseData>(API.USERORDERINFO_URL+`${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`)
}
/**
 * 获取就诊人列表
 */
export const reqAllUser=()=>{
    return request.get<any,AllUserResponseData>(API.ALLUSER_URL)
}
/**
 * 获取所有的订单状态
 */
export const reqAllOrderState=()=>{
    return request.get<any,AllOrderStateResponseData>(API.ORDERSTATE_URL)
}
/**
 * 获取省份数据
 * @param parentId
 */
export const reqCity =(parentId:string)=>{
    return request.get<any,any>(API.CITY_URL+`${parentId}`)
}
/**
 * 添加或更新一个就诊人
 * @param data
 */
export const reqAddOrUpdateUser =(data:AddOrUpdateUser)=>{
    if(data.id){
        return request.put<any,any>(API.UPDATEUSER_URL,data)
    }else {
        return request.post<any,any>(API.ADDUSER_URL,data)
    }
}
/**
 * 删除一个就诊人
 * @param id
 */
export const reqDeleteUser=(id:number)=>{
    return request.delete(API.DELETEUSER_URL+`${id}`)
}